#include<vector>
#include<iostream>
#include<string>
using namespace std;
vector<vector<bool>> visited;
namespace bit
{
    int count = 0;
}
int count = 0;
int row = 0, col = 0;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
void dfs(vector<vector<char>>& grid, int i, int j)
{
    if (i < 0 || i >= row
        || j < 0 || j >= col
        || grid[i][j] != '1'
        || visited[i][j] == true) {
        return;
    }
    visited[i][j] = true;
    for (int k = 0; k < 4; k++) {

        dfs(grid, i + dx[k], j + dy[k]);
    }

}
int numIslands(vector<vector<char>>& grid) {
    row = grid.size();
    col = grid[0].size();
    visited.resize(row);
    for (int i = 0; i < row; i++) {
        visited[i].resize(col);
    }
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            if (visited[i][j] == false &&grid[i][j]=='1') {
                dfs(grid, i, j);
                bit::count++;
            }

        }
    }

    return bit::count;
}

//int main() 
//{
//    vector<vector<char>> nums = {
//        {'1','1','0','0','0'},
//        {'1','1','0','0','0'},
//        {'0','0','1','0','0'},
//        {'0','0','0','1','1'} };
//    bit::count = numIslands(nums);
//    std::cout << bit::count<<endl;
//    
//    return 0;
//}